﻿using Domain.Model;
using Domain.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DTO
{
    public class TaskTakeListOutput
    {
        /// <summary>
        /// TakeTaskID
        /// </summary>
        public int ID { get; private set; }
        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; private set; }
        public SubmitTakeTaskDataDto Data { get; private set; }
        /// <summary>
        /// 审核完成时间
        /// </summary>
        public DateTime? AuditFinishTime { get; private set; }
        public string StatusName { get; private set; }
        public string IMUser { get; private set; }
        public string UserNickName { get; private set; }

        /// <summary>
        /// 审核提交时间
        /// </summary>
        public DateTime? AuditSubmitTime { get; private set; }

        //public static List<TaskTakeListOutput> Parse(List<TaskTakeAggregate> list)
        //{
        //    List<TaskTakeListOutput> taskTakeListOutputs = new List<TaskTakeListOutput>();

        //    foreach (var item in list)
        //    {
        //        taskTakeListOutputs.Add(TaskTakeListOutput.Parse(item));
        //    }

        //    return taskTakeListOutputs;
        //}

        public static TaskTakeListOutput Parse(TaskTakeAggregate item, UserInfoAggregate u, string IMUser)
        {
            TaskTakeListOutput taskTakeListOutput = new TaskTakeListOutput();

            taskTakeListOutput.ID = item.ID;
            taskTakeListOutput.Title = item.GetDataField().FirstOrDefault()?.Text;
            taskTakeListOutput.Data = SubmitTakeTaskDataDto.Parse(item.FromData);

            taskTakeListOutput.AuditFinishTime = item.AuditFinishTime;
            taskTakeListOutput.StatusName = item.Status.ToString();
            taskTakeListOutput.IMUser = IMUser;
            taskTakeListOutput.UserNickName = u.NickName;
            if (item.AuditOutTime.HasValue && item.Status == Domain.Types.TaskTakeAuditStatus.待审核)
            {
                taskTakeListOutput.AuditSubmitTime = item.AuditOutTime.Value.AddHours(-(int)(item.TakeLimitAudit));
            }

            return taskTakeListOutput;
        }
    }
}
